﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test1
{
    class Program
    {
        static Hashtable ha = new Hashtable();
        static List<Student> stu = new List<Student>();
        static void Main(string[] args)
        {
            
            Load();
          
        }
        public static void Load() { 
        
            Console.WriteLine("请选择:1、添加学生信息。2、删除学生信息。3、查询学生信息");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    Add();
                    break;

                case 2:
                    Delete();
                    break;

                case 3:
                    Select();
                    break;
                default:
                    Console.WriteLine("没有这个选项！");
                    break;
            }
        }

        public static void Add() {
            Console.WriteLine("请输入学生的学号:");
            int stuNo = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入学生姓名:");
            string stuName = Console.ReadLine();
            Console.WriteLine("请输入学生年龄:");
            int stuAge = int.Parse(Console.ReadLine());
            Student stu1 = new Student(stuNo, stuName, stuAge);
            if (ha.Contains(stuNo))
            {
                Console.WriteLine("学号重复!");
            }
            else
            {
                ha.Add(stu1.no, stu1);
                stu.Add(stu1);
                Console.WriteLine("添加成功");
                Load();
            }
            
        }

        public static void Delete() {
            Console.WriteLine("请输入学号");
            int a = int.Parse(Console.ReadLine());
            if (ha.Contains(a))
            {
                stu.Remove((Student)ha[a]);
                ha.Remove(a);
                Select();
            }
            else
            {
                Console.WriteLine("没找到");
            }
            

        }

        public static void Select()
        {
            Console.WriteLine("请选择:1、查询所有（学号排序）2、查询所有（姓名排序）3、查询所有（年龄排序）4、按学号查询 5、退出");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    stu.Sort(new NOSort());
                    foreach (var item in stu)
                    {
                        Console.WriteLine(item);
                    }
                    break;

                case 2:
                    stu.Sort(new NameSort());
                    foreach (var item in stu)
                    {
                        Console.WriteLine(item);
                    }
                    break;

                case 3:
                    stu.Sort(new AgeSort());
                    foreach (var item in stu)
                    {
                        Console.WriteLine(item);
                    }
                    break;

                case 4:
                    Console.WriteLine("请输入要查找的学号：");
                    int a = int.Parse(Console.ReadLine());
                    if (ha.Contains(a))
                    {
                        Console.WriteLine(ha[a]);
                    }
                    else
                    {
                        Console.WriteLine("查无此人!");
                    }
                    break;
                case 5:
                    Environment.Exit(0);
                    break;
                default:
                    Console.WriteLine("没有这个选项！");
                    break;
            }
          
        }
    }
}
